<?php
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use app\models\Message;
use app\models\User;

/* @var $this \yii\web\View */
/* @var $content string */

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>

<?php $this->beginBody() ?>
    <div class="wrap">
        <?php
            NavBar::begin([
                'brandLabel' =>yii::t('Site','2048 Online Game'),
                'brandUrl' => Yii::$app->homeUrl,
                'options' => [
                    'class' => 'navbar-default navbar-fixed-top',
                    'style'=>'background-color:#F0F0F0',
                ],
            ]);

            $session = Yii::$app->session;
            $session->open();
            if(!yii::$app->user->isGuest)
            {
                $id = yii::$app->user->identity->user_id;
                $num = Message::find()->where("receiver_id = {$id} and isRead = 1 and status != 1")->count();
            }
            echo Nav::widget([
                'options' => ['class' => 'navbar-nav navbar-right'],
                'encodeLabels'=>false,
                'items' => [
                    ['label' => yii::t('Site','Home'), 'url' => ['/site/index']],
                    ['label' => yii::t('Site','About Us'), 'url' => ['/site/about']],
                    $session['language'] == 'en-US' ?
                    ['label' => '简体中文', 'url' => ['/site/changelanguage']]:
                    ['label' => 'English', 'url' => ['/site/changelanguage']],
                    [
                        'label' => $num == 0 ? yii::t('Site','My Account') : yii::t('Site','My Account').'<span id="message-badge" class="badge">'.$num.'</span>',
                        'url' => ['/site/contact'],
                        'visible'=>!Yii::$app->user->isGuest,
                        'itemOptions'=>[
                            'class'=>'dropdown',
                            'tabindex'=>"-1"
                        ],
                        'linkOptions'=>[
                            'class'=>'dropdown-toggle',
                            'data-toggle'=>"dropdown"
                        ],
                        'items'=>[
                                ['label'=>$num == 0 ? Yii::t('Site', 'My Notice') : Yii::t('Site', 'My Notice').'<span id="message-badge" class="badge">'.$num.'</span>','url'=>['message/inbox']],
                                ['label'=>Yii::t('Site', 'My Profile'),'url'=>['user/profile','name'=>yii::$app->user->identity->user_name]],
                                ['label'=>Yii::t('Site', 'Modify Pwd'),'url'=>['user/changepassword']],
                                yii::$app->user->isGuest ? :
                                ['label'=>Yii::t('Site', 'Email Notice'),'url'=>['message/emailone'], 'visible'=>(yii::$app->user->identity->checkAccess(User::ROLE_ADMIN) || yii::$app->user->identity->checkAccess(User::ROLE_TEACHER))],
                                yii::$app->user->isGuest ? :
                                ['label'=>Yii::t('Site', 'User Manage'),'url'=>['user/index'], 'visible'=>(yii::$app->user->identity->checkAccess(User::ROLE_ADMIN) || yii::$app->user->identity->checkAccess(User::ROLE_TEACHER))],

                            ],
                        ],
                        Yii::$app->user->isGuest ?
                        ['label' => yii::t('Site','Signup'), 'url' => ['/user/signup']] :'',

                            Yii::$app->user->isGuest ?
                            ['label' => yii::t('Site','Login'), 'url' => ['/site/login']] :
                            ['label' => yii::t('Site','Logout').' (' . Yii::$app->user->identity->user_name . ')',
                                'url' => ['/site/logout'],
                                'linkOptions' => ['data-method' => 'post']],
                            ],
                        ]);
            NavBar::end();
?>

        <div class="container">
            <?= Breadcrumbs::widget([
                'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
            ]) ?>
            <?= $content ?>
        </div>
    </div>

    <footer class="footer">
        <div class="container">
            <p class="pull-left">&copy; My Company <?= date('Y') ?></p>
            <p class="pull-right"><?= Yii::powered() ?></p>
        </div>
    </footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
